﻿#pragma once

#include "MapObject.h"
#include "../../Shared/Enums.h"
#include "Frames.h"
#include "../../Shared/Data/ClientData.h"
#include "../../Shared/ServerPackets.h"
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include "../../stringhelper.h"

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirScenes;
namespace S = ServerPackets;

namespace Client::MirObjects
{
    class NPCObject : public MapObject
    {
    public:
        virtual ~NPCObject()
        {
            delete Frames;
            delete Frame;
            delete Colour;
        }

        ObjectType getRace() const override;
        bool getBlocking() const override;

        FrameSet *Frames;
        Frame *Frame;

        long long QuestTime = 0;
        int BaseIndex = 0, FrameIndex = 0, FrameInterval = 0, EffectFrameIndex = 0, EffectFrameInterval = 0, QuestIndex = 0;

        unsigned short Image = 0;
        Color *Colour = Color::White;

        QuestIcon QuestIcon = QuestIcon::None;

    private:
        bool _canChangeDir = true;

    public:
        bool getCanChangeDir() const;
        void setCanChangeDir(bool value);

        std::vector<ClientQuestInfo*> Quests;


        NPCObject(unsigned int objectID);

        void Load(S::ObjectNPC *info);

        void LoadLibrary();

        void Process() override;
        virtual void ProcessFrames();
        int UpdateFrame();

        int UpdateFrame2();

        virtual void SetAction();
        void Draw() override;

        bool MouseOver(Point *p) override;

        void DrawBehindEffects(bool effectsEnabled) override;

        void DrawEffects(bool effectsEnabled) override;

        void DrawName() override;

        void CreateNPCLabel(const std::string &word, int wordOrder);


        //Quests

        #pragma region Quest System
        void UpdateBestQuestIcon();

        std::vector<ClientQuestProgress*> GetAvailableQuests(bool returnFirst = false);

        private:
            return *quests;
    };

    public:
        bool CanAccept(ClientQuestInfo *quest);

        #pragma endregion
}
}
